package my.sort.cmp;

import my.sort.Sort;

/**
 * 选择排序
 *
 * @author AJun
 * @date 2020/9/15
 */
public class SelectionSort<T extends Comparable<T>> extends Sort<T> {

    @Override
    protected void sort() {
        int len = array.length;
        for (int end = len - 1; end > 0; end--) {
            int maxIndex = 0;
            for (int begin = 1; begin <= end; begin++) {
                if (cmp(maxIndex, begin) <= 0) {
                    maxIndex = begin;
                }
            }
            swap(maxIndex, end);
        }
    }

}
